package com.im.server.enterprise.business.action;

import javax.annotation.Resource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import com.im.server.enterprise.common.service.DepartmentChatLogService;
import com.im.server.enterprise.common.service.DepartmentChatService;
import com.only.general.annotation.action.ActionMapping;
import com.only.general.annotation.action.MethodMapping;
import com.only.general.annotation.parameter.Define;
import com.only.net.session.SocketSession;
import com.only.query.page.DefaultPage;
import com.onlyxiahui.im.message.Head;
import com.onlyxiahui.im.message.data.PageData;
import com.onlyxiahui.im.message.data.chat.Content;
import com.onlyxiahui.im.message.data.query.ChatQuery;
import com.onlyxiahui.im.message.server.ResultMessage;

@Component
@ActionMapping(value = "1.500")
public class DepartmentChatAction {
	protected final Logger logger = LogManager.getLogger(this.getClass());

	@Resource
	DepartmentChatService departmentChatService;
	@Resource
	DepartmentChatLogService departmentChatLogService;

	@MethodMapping(value = "1.1.5001")
	public void departmentChat(Head head, SocketSession socketSession,
			@Define("userId") String userId,
			@Define("departmentId") String departmentId,
			@Define("content") Content content) {
		String key = head.getKey();
		departmentChatService.departmentChat(key, userId, departmentId, content);
	}

	/**
	 * 获取部门聊天记录
	 * 
	 * @author XiaHui
	 * @date 2017年8月13日 上午10:26:20
	 * @param departmentId
	 * @param chatQuery
	 * @param pageData
	 * @return
	 */
	@MethodMapping(value = "1.1.5004")
	public Object queryRoomChatLog(
			@Define("departmentId") String departmentId,
			@Define("chatQuery") ChatQuery chatQuery,
			@Define("page") PageData pageData) {
		DefaultPage page = new DefaultPage();
		page.setPageSize(pageData.getPageSize());
		page.setPageNumber(pageData.getPageNumber());

		ResultMessage message = departmentChatLogService.queryDepartmentChatContentList(departmentId, chatQuery, page);
		return message;
	}
}
